package com.ww.controller;

import com.ww.common.context.LoginMemberContext;
import com.ww.common.resp.CommonResp;
import com.ww.common.resp.PageResp;
import com.ww.req.PassengerQueryReq;
import com.ww.req.PassengerSaveReq;
import com.ww.resp.PassengerQueryResp;
import com.ww.services.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/passenger")
public class PassengerController {
    private static final Logger LOG= LoggerFactory.getLogger(PassengerController.class);
    @Resource
    private PassengerService passengerService;

    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody PassengerSaveReq req) {
        passengerService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<PassengerQueryResp>> queryList(@Valid PassengerQueryReq req) {
        // 可以直接在线程变量中拿到 memberId
        req.setMemberId(LoginMemberContext.getId());
        PageResp<PassengerQueryResp> list = passengerService.queryList(req);
        return new CommonResp<>(list);
    }

}
